#include "Slave.h"

Slave::Slave(int slave_id, int _pool_size, int _master_id, int bufferSize, Job *_job){
	this->id = slave_id;
	this->pool_size = _pool_size;
	this->master_id = _master_id;
	this->job = _job;
	
	this->buffer = new char[bufferSize];
	
	MPI_Request request;
	MPI_Status status;
	
	// Oczekiwanie na "pakiet"
	printf("RANK%d: Receiving \n", this->id);
	MPI_Irecv (buffer, sizeof(buffer), MPI_CHAR, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD,
		           &request);
	MPI_Wait (&request, &status);
	
	printf("RANK%d: Received from \n", this->id);
	this->WorkerThread(buffer);
}

void Slave::WorkerThread(char *buffer){
	
	// zewnetrzna klasa wykona dzialania na odebranych danych
	this->job->Run(buffer, sizeof(buffer));
	
	// odeslanie wyniku do master_id
	// MPI_Isend
}
